package com.ssoserver.config;

import com.ssoserver.pojo.MyUserDetails;
import com.ssoserver.service.UserService;
import com.ssoserver.utils.JsonAndView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class MyCustomUserService implements UserDetailsService {
    @Autowired
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //验证用户名密码是否正确
        Integer byUserName = userService.findByUserName(username);
        if (byUserName <= 0){
            return new MyUserDetails();
        }
        MyUserDetails details = new MyUserDetails();
        details.setUsername(username);
        details.setPassword("123456");
        return details;
    }
}
